package listener;

import java.sql.Connection;

import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.sql.DataSource;

import utils.DBUtil;

/**
 * Application Lifecycle Listener implementation class DBInitListener
 *
 */
public class DBInitListener implements ServletContextListener {

    /**
     * Default constructor. 
     */
    public DBInitListener() {
        // TODO Auto-generated constructor stub
    }

    public void contextInitialized(ServletContextEvent sce) {
    	DataSource ds;
		try {
			InitialContext cxt = new InitialContext();
			ds = (DataSource) cxt.lookup( "java:/comp/env/jdbc/myoracle" );
			DBUtil.setDataSource(ds);
		} catch (Exception e) {
			e.printStackTrace();
		}
    }

	/**
     * @see ServletContextListener#contextDestroyed(ServletContextEvent)
     */
    public void contextDestroyed(ServletContextEvent sce) {
    }
	
}
